﻿Public Class ViewParametrageAvance

    Private Sub BtSetCles_Click(sender As Object, e As Windows.RoutedEventArgs) Handles BtSetCles.Click



        Dim vm As ViewModelParametrageAvance = DataContext

        Dim errorconv As Boolean = False
        Dim v As Double
        Try
            v = Convert.ToDouble(txtValue.Text)
        Catch ex As Exception
            errorconv = True
        End Try

        If errorconv Then Return

        Dim table As DataModel.PmtDataset.ParametrageAvanceDataTable = vm.ParametrageAvance.Table

        For Each elt As DataRowView In ClesDGrid.SelectedItems
            ' vm.ParametrageAvance.Table.Rows.Add(elt(0), elt(1), elt(2), elt(3), vm.Parametre, v)
            Dim row = table.FindByGroupeParametreAnneeGenerationCode_Garantie( _
                        elt("Groupe"), _
                        vm.Parametre, _
                        elt("Annee"), _
                        elt("Generation"), _
                        elt("Code_Garantie"))
            If row Is Nothing Then
                table.AddParametrageAvanceRow(elt("Groupe"), elt("Code_Garantie"), elt("Generation"), elt("Annee"), vm.Parametre, v)
            Else
                row.Valeur = v
            End If
        Next
    End Sub

    Private Sub BtUnSetCles_Click(sender As Object, e As Windows.RoutedEventArgs) Handles BtUnSetCles.Click

        Dim vm As ViewModelParametrageAvance = DataContext

        For Each elt As DataRowView In ClesParamDGrid.SelectedItems
            vm.ParametrageAvance.Table.Rows.Remove(elt.Row)
        Next
    End Sub
End Class
